import Vue from 'vue'
import VueRouter from 'vue-router'
import {Message} from 'element-ui';

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'login',
    component: () => import(/* webpackChunkName: "about" */ '../views/login.vue')
  },
  {
    path: '/index',
    name: 'index',
    component: () => import(/* webpackChunkName: "about" */ '../views/index')
  },
]

const router = new VueRouter({
  routes
})

router.beforeEach((to, from, next) => {
  if (to.path == '/') {
    next();
  } else {
    let token = sessionStorage.getItem("token");
    if (token) {
      next();
    } else {
      Message.error('已注销');
      next("/");
    }
  }

})
export default router
